package fun.werfamily.wf.auth.core.feign.client;

import fun.werfamily.wf.auth.core.dto.VerifyCodeReqDTO;
import fun.werfamily.wf.auth.core.feign.UserRemoteService;
import fun.werfamily.wf.auth.core.feign.dto.UserInfoDTO;
import fun.werfamily.wf.auth.core.feign.dto.UserInfoReqDTO;
import fun.werfamily.wf.base.vo.Result;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Mr.WenMing Zhang
 * @Date: 2023-04-03 21:32
 * @Description:
 */
@Service
@Slf4j
public class UserCoreClient {

    @Resource
    private UserRemoteService userRemoteService;

    public UserInfoDTO getUserInfo(String userName){
        try {
            UserInfoReqDTO userInfoReqDTO = new UserInfoReqDTO();
            userInfoReqDTO.setUserName(userName);
            Result<UserInfoDTO> result = userRemoteService.getUserInfo(userInfoReqDTO);
            if (result != null && result.isSuccess()) {
                return result.getData();
            }
        }catch (Exception exception){
            log.error("远程调用user-core[/user-core/info]异常,req={}", userName, exception);
            return null;
        }
        return null;
    }

    public Boolean checkVerifyCode(VerifyCodeReqDTO verifyCodeReqDTO){
        try {
            Result<Boolean> result = userRemoteService.checkVerifyCode(verifyCodeReqDTO);
            if (result != null && result.isSuccess()) {
                return result.getData();
            }
        }catch (Exception exception){
            log.error("远程调用user-core[/user-core/checkVerifyCode]异常,req={}", verifyCodeReqDTO, exception);
            return Boolean.FALSE;
        }
        return Boolean.FALSE;
    }
}
